package com.youjiang.meeting.service.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.support.destination.DynamicDestinationResolver;
import org.springframework.stereotype.Service;

import com.youjiang.meeting.bean.TheGameRanking;
import com.youjiang.meeting.controller.ManagerSendInformaction;
import com.youjiang.meeting.mapper.PacketRecordMapper;
import com.youjiang.meeting.mapper.ProgramMapper;
import com.youjiang.meeting.mapper.RedpackMapper;
import com.youjiang.meeting.mapper.SystemErrMapper;
import com.youjiang.meeting.mapper.TUserMapper;
import com.youjiang.meeting.mapper.ThegameMapper;
import com.youjiang.meeting.mapper.UserInfoMapper;
import com.youjiang.meeting.mapper.VoitInfoMapper;
import com.youjiang.meeting.mapper.VoitMapper;
import com.youjiang.meeting.mapper.WxconfigMapper;
import com.youjiang.meeting.po.PacketRecord;
import com.youjiang.meeting.po.Program;
import com.youjiang.meeting.po.ProgramExample;
import com.youjiang.meeting.po.Redpack;
import com.youjiang.meeting.po.RedpackExample;
import com.youjiang.meeting.po.SystemErr;
import com.youjiang.meeting.po.TUser;
import com.youjiang.meeting.po.Thegame;
import com.youjiang.meeting.po.UserInfo;
import com.youjiang.meeting.po.Voit;
import com.youjiang.meeting.po.VoitExample;
import com.youjiang.meeting.po.VoitInfo;
import com.youjiang.meeting.po.VoitInfoExample;
import com.youjiang.meeting.po.Wxconfig;
import com.youjiang.meeting.po.WxconfigExample;
import com.youjiang.meeting.service.ControlService;
import com.youjiang.meeting.service.WeiXinMassegeService;
import com.youjiang.meeting.utils.ComparatorGameRanking;
import com.youjiang.meeting.utils.RedPackDistribution;
import com.youjiang.meeting.utils.StringKeyValue;
import com.youjiang.meeting.utils.ToolUtils;
import com.youjiang.meeting.utils.weixin.SendRedPack;
import com.youjiang.meeting.utils.weixinbean.ShowResult;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * <p>
 * Title: ControlServiceImpl
 * </p> 
 * <p>
 * Description:TODO
 * </p> 
 * <p>
 * Company: weiji
 * </p> 
 *
 * @author feng
 * @date 2016年12月2日 下午4:13:06
 * @version 1.0
 */
@Service
public class ControlServiceImpl implements ControlService{
	
	public static Map<String,TheGameRanking> gameAnswer;
	/***
	 * 投票结果
	 */
	public static Map<String,Integer> voitMap;
	/***
	 * 投票人
	 */
	public static Map<String , Integer> voitMapUser;
	public static Map<Integer,Integer> voitToNum;
	public static int gameid;
	public static List<Integer> redList;
	public Redpack redpack;
	public static Map<String,Integer> redPackUser;
	public static Map<String,Integer> redPackToUser;
	public static Map<String,Integer> redPackToOpenid;
	public static Random random=new Random();
	private  String send_name;
	private  static String act_name="微信红包";
	private String remark;
	private Integer synchronizedred = 0;
	
	static{
//		random=new Random();
//		gameAnswer=new HashMap<String,TheGameRanking>();
//		voitMap = new HashMap<String,Integer>();
//		voitMapUser = new HashMap<String,Integer>();
//		voitToNum=new HashMap<Integer,Integer>();
////		redList=new ArrayList<Integer>();
//		redPackUser =new HashMap<String,Integer>();
//		redPackToUser=new HashMap<String,Integer>();
//		redPackToOpenid=new HashMap<String,Integer>();
	}
	@Resource
	private WeiXinMassegeService weixinService;
	@Resource
	private ProgramMapper programMapper;
	@Resource
	private ThegameMapper gameMapper;
	@Resource
	private RedpackMapper redpackMapper;
	@Resource
	private TUserMapper userMapper;
	@Resource
	private SystemErrMapper logMapper;
	@Autowired
	private PacketRecordMapper packetRecordMapper;
	@Autowired
	private VoitMapper voitMapper;
	@Autowired
	private VoitInfoMapper vMapper;
	@Autowired
	private WxconfigMapper wxConfig;
	@Autowired
	private UserInfoMapper infoMapper;
	
	
	public void addGameAnswer(TheGameRanking ranking){
		try{
			TheGameRanking theGameRanking = gameAnswer.get(ranking.getOpenid());
			if(theGameRanking==null){
				gameAnswer.put(ranking.getOpenid(), ranking);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	@Override
	public void addVoit(String id, String openid) {
		synchronized (voitMap) {
		try{
			Integer integer = voitMapUser.get(openid);
			//判断是否已经投票
			if(integer==null){
				Integer num=voitMap.get(StringKeyValue.voit+id);
				if(num!=null){
					num=num+1;
					voitMap.put(StringKeyValue.voit+id, num);
					voitMapUser.put(openid, 1);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
		
	}

	@Override
	public String startVoit(HttpSession session) {
		JSONObject json=new JSONObject();
		UserInfo info = (UserInfo) session.getAttribute("userInfo");
		if(info==null){
			return ToolUtils.json(json, "00", "登录超时");
		}
		ProgramExample pexample = new ProgramExample();
		ProgramExample.Criteria criteria = pexample.createCriteria();
		criteria.andUseridEqualTo(info.getId());
		List<Program> selectByExample = programMapper.selectByExample(pexample);
		if(selectByExample!=null && selectByExample.size()>0){
			for(Program p:selectByExample){
				if(p!=null){
					VoitExample vexample = new VoitExample();
					VoitExample.Criteria vcriteria = vexample.createCriteria();
					vcriteria.andProgramidEqualTo(p.getId());
					List<Voit> voitList = voitMapper.selectByExample(vexample);
					if(voitList!=null && voitList.size()>0){
						Voit voit = voitList.get(0);
						
						if(voit.getLevel()==-1){
							return ToolUtils.json(json, "01", "当前投票已经结束");
						}
						try{
							voit.setKeyword("投票");
							voit.setLevel(1);
							voitMapper.updateByPrimaryKey(voit);
						}catch(Exception e){
							return ToolUtils.json(json, "03", "数据出错");
						}	
					}
					
				}
			}
			json.put("code", 2);
			json.put("type", 2010);
			json.put("result", selectByExample);
			ManagerSendInformaction.send(json.toString());
		}
			
		return ToolUtils.json(json, "10", "开始投票成功,请在公众号回复投票的序号");
		
	}


	public String endVoid(HttpSession session) {
		JSONObject json=new JSONObject();
		UserInfo info = (UserInfo) session.getAttribute("userInfo");
		if(info==null){
			return ToolUtils.json(json, "00", "登录超时");
		}

		try{
			ProgramExample example = new ProgramExample();
			ProgramExample.Criteria criteria = example.createCriteria();
			criteria.andUseridEqualTo(info.getId());
			List<Program> selectByExample = programMapper.selectByExample(example);
			for(Program it: selectByExample){
				VoitExample vExample = new VoitExample();
				VoitExample.Criteria vcriteria = vExample.createCriteria();
				vcriteria.andProgramidEqualTo(it.getId());
				List<Voit> voitList = voitMapper.selectByExample(vExample);
				if(voitList!=null && voitList.size()>0){
					Voit voit = voitList.get(0);
					voit.setLevel(-1);
					voitMapper.updateByPrimaryKey(voit);
				}
			}
			/**
			 * 
			 * 结束投票时将set集合中的元素设置为空
			 * 
			 */
			Map<Object,Integer> map = new HashMap<>();
			if(!WeiXinMassegeServiceImpl.set.isEmpty()){
//				Set<Integer> list = WeiXinMassegeServiceImpl.set;
//				if(list!=null && list.size()>0){
//					for(int i:list){
//						Program program = programMapper.selectByPrimaryKey(i);
//						if(program!=null){
//							VoitInfoExample evxample = new VoitInfoExample();
//							VoitInfoExample.Criteria mcriteria = evxample.createCriteria();
//							mcriteria.andProgramidEqualTo(program.getId());
//							List<VoitInfo> infos = vMapper.selectByExample(evxample);
//							if(infos!=null && infos.size()>0){
//								int size = infos.size();
//								map.put(program, size);
//							}
//						}
//						
//					}
//				}
//				WeiXinMassegeServiceImpl.set.clear();
			}
			
			json.put("code", 1);
			json.put("msg", "投票结束");
			json.put("type", 2002);
			
			selectByExample=programMapper.selectByExample(example);
			json.put("result", selectByExample);
//			weixinService.send(json.toString(), null);
			return json.toString();
		}catch(Exception e){
			e.printStackTrace();
			json.put("code", 01);
			json.put("msg", "未知错误");
			json.put("type", 2002);
			return json.toString();
		}
	}

//	@Override
//	public String startGame(Integer id) {
//		JSONObject json=new JSONObject();
//		if(weixinService.getGame()){
//			json.put("code", 0);
//			json.put("des", "有竞猜游戏进行中");
//			return json.toString();
//		}
//		try{
//			Thegame game = gameMapper.selectByPrimaryKey(id);
//			if(game==null){
//				json.put("code", 0);
//				json.put("des", "没找到游戏");
//				return json.toString();
//			}
//			weixinService.setTheGameAnswer(game.getAnswer());
//			weixinService.setGame(true);
//			gameid=game.getId();
//			json.put("code", 1);
//			json.put("type", 2004);
//			json.put("result", "竞猜游戏开始了，请在公众号上回复你心中的答案");
//			weixinService.send(json.toString(), null);
//			json.put("des", game.getName()+"开始"+"，答案为："+game.getAnswer());
//			return json.toString();
//		}catch(Exception e){
//			e.printStackTrace();
//		}
//		json.put("code", 0);
//		json.put("des", "未知错误");
//		return json.toString();
//	}

	@Override
	public String endGame() {
		JSONObject json=new JSONObject();
		weixinService.setTheGameAnswer("");
		weixinService.setGame(false);
		if(gameid>0){
			try{
				Thegame thegame = gameMapper.selectByPrimaryKey(gameid);
				List<TheGameRanking> gameRanking=new ArrayList<TheGameRanking>();
				Set<String> keySet = gameAnswer.keySet();
				for(String key:keySet){
					gameRanking.add(gameAnswer.get(key));
				}
				ComparatorGameRanking comparator=new ComparatorGameRanking();
				Collections.sort(gameRanking, comparator);
				JSONArray array=new JSONArray();
				if(gameRanking.size()>5){
					for(int i=0;i<5;i++){
						array.add(gameRanking.get(i));
					}
				}else{
					array=JSONArray.fromObject(gameRanking);
				}
				thegame.setResultCode(array.toString());
				gameMapper.updateByPrimaryKey(thegame);
				gameAnswer.clear();
				gameid=0;
				json.put("code", 1);
				json.put("des", "成功结束游戏："+thegame.getName());
				return json.toString();
			}catch(Exception e){
				e.printStackTrace();
			}
		}else{
			json.put("code", 0);
			json.put("des", "没有竞猜游戏进行中");
			return json.toString();
		}
		
		json.put("code", 0);
		json.put("des", "未知错误");
		return json.toString();
	}

	@Override
	public String startRed(HttpSession session,Integer id) {
		JSONObject json=new JSONObject();
		UserInfo info = (UserInfo) session.getAttribute("userInfo");
		if(info==null){
			return ToolUtils.json(json, "00", "用户登录超时");
		}
		
		RedpackExample example = new RedpackExample();
		RedpackExample.Criteria criteria = example.createCriteria();
		criteria.andUseridEqualTo(info.getId());
		List<Redpack> redpackList = redpackMapper.selectByExample(example);
		//判断之前的红包是否正在进行中
		boolean flag = false;
		if(redpackList!=null && redpackList.size()>0){
			for(Redpack redpack:redpackList){
				if(redpack.getLevel()==1){
					flag = true;
					break;
				}
			}
			if(flag){
				return ToolUtils.json(json, "01", "上一轮红包还没有结束,请先结束上一轮红包");
			}
		}
		Redpack redpack = redpackMapper.selectByPrimaryKey(id);
		if(redpack==null){
			return ToolUtils.json(json, "02", "没有红包记录");
		}else{
			if (redpack.getLevel()==-1) {
				return ToolUtils.json(json, "03", "这轮红包已经结束了，不可开始");
			}
			this.redpack=redpack;
			System.out.println("redpack------"+redpack);
			RedPackDistribution distribution=new RedPackDistribution();
			System.out.println("distribution---"+distribution);
			try {
				//分配红包金额
				/**
				 * 
				 * 将分配的红包保存在数据库中
				 * 如果多个用户的粉丝来领红包，区分各个用户的粉丝有三种方法
				 *    1,将红包保存在数据库中，然后用户来领红包就去数据库中取一个数额然后将这个金额从数据库中删除
				 *    2,使用map结构首先根据微信文档接口获得该公众号的粉丝的openid然后将这个openid作为map的健，然后为每一个openid设置一个值，这样粉丝来领红包时
				 *      只要根据粉丝的openid来领取金额就可以了  
				 *    3,将用户与分配的红包绑定起来,这样就可以实现在该用户下的红包只能由该用户的粉丝领取
				 */
				
				redList = distribution.getRedPackDistribution(redpack.getNum(), redpack.getAmount());
				redList = Collections.synchronizedList(redList);
				//将红包列表保存在session中
//				session.setAttribute(info.getId()+"", redList);
				
				if(redList.size()!=redpack.getNum()){
					return ToolUtils.json(json, "04", "分配红包出错");
				}else{
					if(StringUtils.isEmpty(send_name)||StringUtils.isEmpty(act_name)||StringUtils.isEmpty(remark)){
						return ToolUtils.json(json, "05", "公司名或活动名或备注为空");
					}
					
					//更新状态
					redpack.setLevel(1);
					redpackMapper.updateByPrimaryKey(redpack);

					json.put("code", 1);
					json.put("msg", "红包开始成功");
					json.put("type", 2003);
					json.put("pas", "红包口令："+redpack.getPas());
					
//					WeiXinMassegeServiceImpl.theReadPackUrl=WeiXinMassegeServiceImpl.theRedPackRob.replace("REDPACK", String.valueOf(redpack.getId()));
					WxconfigExample wexample = new WxconfigExample();
					WxconfigExample.Criteria wxcriteria = wexample.createCriteria();
					wxcriteria.andUseridEqualTo(info.getId());
					List<Wxconfig> cinfig = wxConfig.selectByExample(wexample);
					if(cinfig!=null && cinfig.size()>0){
						Wxconfig c = cinfig.get(0);
						weixinService.send(json.toString(), null,c.getAppid(),c.getApsecrect(),c.getOriginid());
					}
					
					return json.toString();
				}
			} catch (Exception e) {
				e.printStackTrace();
				return ToolUtils.json(json, "04", "分配红包出错");
			}
			
		}
	}

	@Override
	public String endRed(HttpSession session,Integer id) {
		JSONObject json=new JSONObject();
		UserInfo info = (UserInfo) session.getAttribute("userInfo");
		if(info==null){
			return ToolUtils.json(json, "00", "登录超时");
		}	
		RedpackExample example = new RedpackExample();
		RedpackExample.Criteria criteria = example.createCriteria();
		criteria.andUseridEqualTo(info.getId());
		criteria.andIdEqualTo(id);
		List<Redpack> redpackList = redpackMapper.selectByExample(example);
		Redpack redpack = null;
	
		if(redpackList!=null && redpackList.size()>0){
			redpack = redpackList.get(0);
			if(redpack.getLevel()==0){
				return ToolUtils.json(json, "02", "当前红包还未开始,不能结束");
			}
		}else{
			return ToolUtils.json(json, "01", "当前红包不存在");
		}

		if(redpack.getLevel()==-1){
			return ToolUtils.json(json, "01", "当前红包以结束");
		}
		redpack.setLevel(-1);
		redpackMapper.updateByPrimaryKey(redpack);
		if(redList==null){
			return ToolUtils.json(json, "01", "请开始新一轮红包");
		}
		System.out.println("redList-----------"+redList);
		if(redList.size()==0){
			return ToolUtils.json(json, "1", "红包结束成功，红包都抢光了");
		}else{
			int sum=redList.size();
			return ToolUtils.json(json, "1", "红包结束成功，还有"+sum+"个没抢");
		}
//		}
	}

	@Override
	public int getGame() {
		return gameid;
	}
	public int sum=0;
	@Override
	public String sendRedPack(String openid, Integer id,HttpServletRequest req,String money) {
		synchronized (random) {
			System.out.println("money--------"+money);
			int amount = Integer.parseInt(money);
			JSONObject json=new JSONObject();
			if(StringUtils.isEmpty(openid)){
				return ToolUtils.json(json, "0", "进入了二次元数据");
			}
			Redpack redpack = redpackMapper.selectByPrimaryKey(id);
			if(redpack==null){
				return ToolUtils.json(json, "0", "当前红包不存在");
			}
			if(redpack.getLevel()==-1){
				return ToolUtils.json(json, "0", "手速太慢了，这轮红包已经结束");
			}
			if(redpack.getLevel()==0){
				return ToolUtils.json(json, "0", "红包还未开始");
			}

			//发红包
			Map<String, String> send = SendRedPack.send(req, send_name, openid, amount, redpack.getPas(), act_name, remark);
			String return_code=send.get("return_code");
			if(return_code.equalsIgnoreCase("success")){
				String result_code=send.get("result_code");
//				redPackUser.remove(openid);
				if(result_code.equalsIgnoreCase("success")){
					json.put("code", 1);
					json.put("msg", "红包已经发出，请到公众号领红包");
					/**
					 * 
					 * 将领取红包的记录添加到数据库中
					 * 
					 * 
					 */
					PacketRecord record = new PacketRecord();
					record.setAmount(Long.parseLong(send.get("total_amount")));
					record.setOpenid(send.get("re_openid"));
					record.setPacketid(id);
					
					packetRecordMapper.insert(record);
					return json.toString();
				}else{
					String	return_msg=send.get("return_msg");
					String err_code=send.get("err_code");
					SystemErr err=new SystemErr();
					err.setErrCode(err_code);
					err.setOpenid("{\"openid\":"+openid+",\"amount\":"+((double)amount/100)+"}");
					err.setName("红包发送错误");
					err.setErrDes(return_msg);
					logMapper.insert(err);
				}
			}
			return ToolUtils.json(json, "0", "红包发送失败");
		}
//		}
	}
	
	@Override
	public String requestRedPack(String openid, Integer id,HttpServletRequest req) {
		synchronized (redList) {
			JSONObject json = new JSONObject();
			if(StringUtils.isEmpty(openid)){
				return "error";
			}
			if(id==null){
				return "error";
			}
			Redpack redpack = redpackMapper.selectByPrimaryKey(id);
			if(redpack==null){
				return ToolUtils.json(json, "0", "当前红包不存在");
			}
			if(redpack.getLevel()==-1){
				return ToolUtils.json(json, "0", "手速太慢了，这轮红包已经结束");
			}
			if(redpack.getLevel()==0){
				return ToolUtils.json(json, "0", "红包还未开始");
			}	
			int leng=redList.size()-1;
			int money=redList.get(leng);
			req.setAttribute("money", money);
			Integer remove = redList.remove(leng);
			System.out.println("redList.size():"+leng);
			
			
			System.out.println("money:"+money);
			System.out.println("remove:"+remove);
			return money+"";		
		}
		
		
	}

	@Override
	public String setName(String sendName, String actName, String remark) {
		JSONObject json=new JSONObject();
		if(StringUtils.isEmpty(sendName.trim())||StringUtils.isEmpty(actName.trim())||StringUtils.isEmpty(remark.trim())){
			
			json.put("code", 0);
			json.put("msg", "公司名或活动名称或备注为空");
			return json.toString();
		}
		send_name=sendName;
		act_name=actName;
		this.remark=remark;
		json.put("code", 1);
		json.put("msg", "设置成功");
		return json.toString();
	}

	@Override
	public String showWindow(HttpSession session,Integer id, Integer level) {
		JSONObject json=new JSONObject();
		UserInfo info = (UserInfo) session.getAttribute("userInfo");
		if(info==null){
			return ToolUtils.json(json, "00", "登录超时");
		}
		int userid = info.getId();
		//显示投票结果
		if(level==1){
			Map<Object,Object> map = new HashMap<>();
			if(!WeiXinMassegeServiceImpl.set.isEmpty()){
				Set<Integer> list = WeiXinMassegeServiceImpl.set;
				if(list!=null && list.size()>0){
					for(int i:list){
						Program program = programMapper.selectByPrimaryKey(i);
						if(program!=null){
							//将投票的级别设置为2表示公布结果
							VoitExample v = new VoitExample();
							VoitExample.Criteria criteria = v.createCriteria();
							criteria.andProgramidEqualTo(program.getId());
							List<Voit> voitList = voitMapper.selectByExample(v);
							if(voitList!=null && voitList.size()>0){
								Voit voit = voitList.get(0);
								voit.setLevel(2);
								voit.setKeyword("投票结果");
								voitMapper.updateByPrimaryKey(voit);
							}
							
							
							VoitInfoExample evxample = new VoitInfoExample();
							VoitInfoExample.Criteria mcriteria = evxample.createCriteria();
							mcriteria.andProgramidEqualTo(program.getId());
							List<VoitInfo> infos = vMapper.selectByExample(evxample);
							if(infos!=null && infos.size()>0){
								
								ShowResult p = new ShowResult();
								p.setName(program.getName());
								p.setPrincipal(program.getPrincipal());
								p.setSize(infos.size());
								map.put(program.getName(), p);
							}
						}
						
					}
					/**
					 * 
					 * 将投票后的结果显示到微信墙上
					 */
					
					
					
					json.put("code", 1);
					json.put("type", 2001);
					json.put("result", map);
					System.out.println("ManagerSendInformaction-----"+json.toString());
//					WeiXinMassegeServiceImpl.sendVoitResultToUser(json.toString());
					weixinService.sendVoitResultToUser(json.toString());
					ManagerSendInformaction.send(json.toString());
					
					/**
					 * 
					 * 将投票记录删除
					 * 根据级别level查询如果级别为2表示已经投过票了将voit_info表里的记录删除
					 * 首先遍历voit_info的记录然后利用programId去voit表查，如果级别为2就删除voit_info的记录
					 */
					ProgramExample example = new ProgramExample();
					ProgramExample.Criteria criteria = example.createCriteria();
					criteria.andUseridEqualTo(userid);
					List<Program> pList = programMapper.selectByExample(example);
					if(pList!=null && pList.size()>0){
						for(Program p:pList){
							VoitInfoExample vexample = new VoitInfoExample();
							VoitInfoExample.Criteria vcriteria = vexample.createCriteria();
							vcriteria.andProgramidEqualTo(p.getId());
							List<VoitInfo> infos = vMapper.selectByExample(vexample);
						    if(infos!=null && infos.size()>0){
						    	for(VoitInfo vinfo:infos){
						    		vMapper.deleteByPrimaryKey(vinfo.getId());
						    	}
						    }
						}
	
					}
				}
//				WeiXinMassegeServiceImpl.set.clear();
				
			}
			
		}
		//显示游戏排名
		if(level==2){
			Thegame thegame = gameMapper.selectByPrimaryKey(id);
			if(thegame==null){
				json.put("code", 0);
				json.put("des", "没有找到竞猜游戏");
				return json.toString();
			}
			if(thegame.getResultCode()==null){
				json.put("code", 0);
				json.put("des", "竞猜游戏没有回答人");
				return json.toString();
			}
			JSONArray array=JSONArray.fromObject(thegame.getResultCode());
			/*if(array.size()==0){
				json.put("code", 0);
				json.put("des", "竞猜游戏没有回答人");
				return json.toString();
			}*/
			json.put("title", thegame.getName());
			json.put("solution", thegame.getAnswer());
			json.put("code", 1);
			json.put("type", 2005);
			json.put("result", array);
			ManagerSendInformaction.send(json.toString());
			json.put("des", "显示成功");
			json.remove("result");
			return json.toString();
		}
		return json.toString();
	}

	@Override
	public String hideWindow(HttpSession session) {
		JSONObject json=new JSONObject();
		UserInfo info = (UserInfo) session.getAttribute("userInfo");
		if(info==null){
			return ToolUtils.json(json, "00", "登录超时");
		}
		int userid = info.getId();
		if(!WeiXinMassegeServiceImpl.set.isEmpty()){
			Set<Integer> list = WeiXinMassegeServiceImpl.set;
			if(list!=null && list.size()>0){
				for(int i:list){
					Program program = programMapper.selectByPrimaryKey(i);
					if(program!=null){
						//将投票的级别设置为3表示公布结果
						VoitExample v = new VoitExample();
						VoitExample.Criteria criteria = v.createCriteria();
						criteria.andProgramidEqualTo(program.getId());
						List<Voit> voitList = voitMapper.selectByExample(v);
						if(voitList!=null && voitList.size()>0){
							Voit voit = voitList.get(0);
							voit.setLevel(3);
							voit.setKeyword("关闭结果");
							voitMapper.updateByPrimaryKey(voit);
						}
					}
				}
			}
			WeiXinMassegeServiceImpl.set.clear();
		}
		json.put("code", 1);
		json.put("type",3001);
		json.put("des", "关闭成功");
		ManagerSendInformaction.send(json.toString());
		return json.toString();
	}

	@Override
	public String getName() {
		JSONObject json=new JSONObject();
		json.put("company", send_name);
		json.put("actname", act_name);
		json.put("remark", remark);
		return json.toString();
	}

	@Override
	public String closeWindow() {
		JSONObject json=new JSONObject();
		json.put("type", 2007);
		ManagerSendInformaction.send(json.toString());
		json.put("code", 1);
		json.put("des", "已经清空");
		return json.toString();
	}

	@Override
	public String reloadWindow() {
		JSONObject json=new JSONObject();
		json.put("type", 2008);
		ManagerSendInformaction.send(json.toString());
		json.put("code", 1);
		json.put("des", "重新开始");
		return json.toString();
	}
}
